﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace dotUML.Core.Common
{
    /// <summary>
    /// Base abstract class for diagrams.
    /// </summary>
    class DiagramBase : IDiagram
    {
        #region IDiagram Members

        string _name;
        EDiagramType _diagramType;

        /// <summary>
        /// Diagram name.
        /// </summary>
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }

        /// <summary>
        /// Diagram type.
        /// </summary>
        public EDiagramType DiagramType
        {
            get
            {
                return _diagramType;
            }
            set
            {
                _diagramType = value;
            }
        }

        #endregion

        Dictionary<string, IDiagramElement> _elements;
        Model _parentModel;

        /// <summary>
        /// List of diagram elements.
        /// </summary>
        public Dictionary<string, IDiagramElement> Elements
        {
            get 
            { 
                return _elements; 
            }
            set 
            { 
                _elements = value; 
            }
        }

        /// <summary>
        /// Model to which the diagram belongs.
        /// </summary>
        public Model ParentModel
        {
            get 
            { 
                return _parentModel; 
            }
            set 
            { 
                _parentModel = value; 
            }
        }

        /// <summary>
        /// Class constructor.
        /// </summary>
        public DiagramBase()
        {
            Elements = new Dictionary<string, IDiagramElement>();
        }

        /// <summary>
        /// Add a diagram element. If an element with the same name 
        /// already exists in the diagram, throws exception.
        /// </summary>
        /// <param name="Element">Diagram element.</param>
        public void AddElement(IDiagramElement Element)
        {
            if (ElementExists(Element.Name))
            {
                throw new CommonException(string.Format(Resources.DiagramBase_AddElement_AlreadyExists, Name));
            }

            Elements.Add(Element.Name, Element);
        }

        /// <summary>
        /// Check whether an alement with the provided name already
        /// exists in the diagram.
        /// </summary>
        /// <param name="Name">Element name.</param>
        /// <returns>True if element exists, otherwise - false.</returns>
        public bool ElementExists(string Name)
        {
            return Elements.ContainsKey(Name);
        }

        /// <summary>
        /// Resolve proxy elements with real ones.
        /// </summary>
        /// <returns>True if all proxy elements were resolved, otherwise - false.</returns>
        public bool ResolveProxies()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Validates the diagram.
        /// </summary>
        /// <returns>True if the validation was successful, otherwise - false.</returns>
        public bool Validate()
        {
            throw new NotImplementedException();
        }

    }
}
